package com.sc.nft.service.impl;

import com.sc.nft.dao.BuyCollectionDiscountDao;
import com.sc.nft.entity.BuyCollectionDiscount;
import com.sc.nft.entity.vo.BuyCollectionDiscountListVO;
import com.sc.nft.service.BuyCollectionDiscountService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 服务接口实现
 *
 * @author Sun
 * @since 2022-08-19 11:28:22
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class BuyCollectionDiscountServiceImpl implements BuyCollectionDiscountService {
    private final BuyCollectionDiscountDao buyCollectionDiscountDao;

    @Override
    public List<BuyCollectionDiscountListVO> buyCollectionDiscountList(Long id) {
        List<BuyCollectionDiscountListVO>listVOS=  buyCollectionDiscountDao.buyCollectionDiscountList(id);
        for (BuyCollectionDiscountListVO listVO : listVOS) {
            BigDecimal buyFirstNum = listVO.getBuyFirstNum();
            BigDecimal bigDecimal = buyFirstNum.movePointRight(1).stripTrailingZeros();
            listVO.setBuyFirstNum(bigDecimal);
        }
        return listVOS;
    }

    @Override
    public BuyCollectionDiscount selectByProductIdAndCollectionId(Long productId, Long collectionId) {
        return buyCollectionDiscountDao.selectByProductIdAndCollectionId(productId,collectionId);
    }
}